# archer
# Trump tweets
# data: Trump Twitter Archive

library("lubridate")
library("magrittr")
library("dplyr")
library("gtools")
library("foreign")
library("haven")

# load foxratingstweets.dta 
FNCtweets <- read_dta("foxratingstweets.dta")
FNCtweets <- as.data.frame(FNCtweets)
FNCtweets$mocount <- as.numeric(FNCtweets$mocount)
objects(FNCtweets)
View(FNCtweets)

molab <- c(1:47)
names(molab)[1] <- "Jan '17"
names(molab)[2] <- "Feb '17"
names(molab)[3] <- "Mar '17"
names(molab)[4] <- "Apr '17"
names(molab)[5] <- "May '17"
names(molab)[6] <- "Jun '17"
names(molab)[7] <- "Jul '17"
names(molab)[8] <- "Aug '17"
names(molab)[9] <- "Sep '17"
names(molab)[10] <- "Oct '17"
names(molab)[11] <- "Nov '17"
names(molab)[12] <- "Dec '17"
names(molab)[13] <- "Jan '18"
names(molab)[14] <- "Feb '18"
names(molab)[15] <- "Mar '18"
names(molab)[16] <- "Apr '18"
names(molab)[17] <- "May '18"
names(molab)[18] <- "Jun '18"
names(molab)[19] <- "Jul '18"
names(molab)[20] <- "Aug '18"
names(molab)[21] <- "Sep '18"
names(molab)[22] <- "Oct '18"
names(molab)[23] <- "Nov '18"
names(molab)[24] <- "Dec '18"
names(molab)[25] <- "Jan '19"
names(molab)[26] <- "Feb '19"
names(molab)[27] <- "Mar '19"
names(molab)[28] <- "Apr '19"
names(molab)[29] <- "May '19"
names(molab)[30] <- "Jun '19"
names(molab)[31] <- "Jul '19"
names(molab)[32] <- "Aug '19"
names(molab)[33] <- "Sep '19"
names(molab)[34] <- "Oct '19"
names(molab)[35] <- "Nov '19"
names(molab)[36] <- "Dec '19"
names(molab)[37] <- "Jan '20"
names(molab)[38] <- "Feb '20"
names(molab)[39] <- "Mar '20"
names(molab)[40] <- "Apr '20"
names(molab)[41] <- "May '20"
names(molab)[42] <- "Jun '20"
names(molab)[43] <- "Jul '20"
names(molab)[44] <- "Aug '20"
names(molab)[45] <- "Sep '20"
names(molab)[46] <- "Oct '20"
names(molab)[47] <- "Nov '20"

#figure 1
par(cex=.8)
plot(FNCtweets$mocount, FNCtweets$attack_bias_pct,
     main="Trump Tweets About Fox News by Month [%]",
     xlab="Month", xaxt='n', ylab="Percent of Total FNC Tweets", 
     ylim=c(0,100), 
     col="red", pch=16)
axis(1, at=seq(1,47, by=1), labels=FALSE)
par(cex=.5)
text(seq(1,47, by=1), par("usr")[4]-111.75, labels=names(molab), srt=45, pos=1, xpd=TRUE)
par(cex=.8)
lines(FNCtweets$mocount, FNCtweets$attack_bias_pct, col="red")
points(FNCtweets$mocount, FNCtweets$praise_pct, col="black", pch=15)
lines(FNCtweets$mocount, FNCtweets$praise_pct, col="black", lty=3)
par(cex=.7)
legend(x=.57,y=102.4, bty="n", c("Negative", "Positive"), pch=c(16,15), lty=c(1,3), col=c("red", "black"), cex=0.7)
segments(7,92,7,105)
segments(-5,92,7,92)


#####################
# descriptive stats #
#####################
mean(FNCtweets$praise_pct[FNCtweets$mocount[1:12]]) 
mean(FNCtweets$praise_pct[FNCtweets$mocount[13:24]]) 
mean(FNCtweets$praise_pct[FNCtweets$mocount[25:36]]) 
mean(FNCtweets$praise_pct[FNCtweets$mocount[37:47]]) #thru nov 7

mean(FNCtweets$attack_bias_pct[FNCtweets$mocount[1:12]]) 
mean(FNCtweets$attack_bias_pct[FNCtweets$mocount[13:24]]) 
mean(FNCtweets$attack_bias_pct[FNCtweets$mocount[25:36]]) 
mean(FNCtweets$attack_bias_pct[FNCtweets$mocount[37:47]]) #thru nov 7

